package com.hr.builder;

import org.springframework.stereotype.Component;

import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.manager.RelatedModel;
import com.espirit.eap.manager.TabbedModel;
import com.espirit.eap.pagelayout.DetailLayout;
import com.espirit.eap.pagelayout.FunctionButton;
import com.hr.BankCollection;
import com.hr.Salary;
import com.hr.SalaryItemBase;
import com.hr.SalaryTicket;

@Component
public class SalaryBuilder extends ModelBuilderSupport {
	static final String EMPLOYEE = "employee";
	static final String ACCTTERM = "acctTerm";
	static final String AMOUNT = "amount";
	static final String DEPARTMENT = "department";
	
	static final String PAYMODEL = "payModel";
	static final String STATE = "state";
	
	static final String CREATEDON = "createdOn";
	static final String CREATED = "created";
	static final String DEPTIDS = "deptIds";
	
	FunctionButton reCalcSalary = null;
	FunctionButton generateBankCollection = null;
//	FunctionButton pay = null;
	
	
	@Override
	public boolean init() {
		return super.setClass(Salary.class, "Salary", "应发工资");
	}

	@Override
	public void buildFields() {
		super.buildFields();
		addModelField(EMPLOYEE, "Employee", "职员");
		addModelField(ACCTTERM, "AcctTerm", "会计期间");
		addModelField(AMOUNT, "Amount", "金额");
		addModelField(DEPARTMENT, "Department", "部门");
		addModelField(DEPTIDS, "Department", "部门");
		
		addModelField(PAYMODEL, "Pay Model", "支付方式");
		addModelField(STATE, "State", "状态");
		
		addModelField(CREATEDON, "Created On", "创建日期");
		addModelField(CREATED, "Created", "创建");
	}
	
	@Override
	public void prepareLayoutElements() {
		reCalcSalary = createFunctionButton("_reCalcSalary", "Recalc Salary", "重算工资",this.clazz,"_reCalcSalary",false,null,null);
		generateBankCollection = createFunctionButton("_generateBankCollection", "Generate Bank Collection", "生成银行托收",this.clazz,"_generateBankCollection",false,null,null);
//		pay = createFunctionButton("_pay", "Pay", "支付工资",this.clazz,"_pay",false,null,null);
		super.prepareLayoutElements();
	}
	
	@Override

	protected void setDefaultLayoutButtons() {
		addButton(FunctionButton.EXPORT);
	}
	
	@Override
	protected void addExtraListLayoutButtons() {
		addButton(reCalcSalary);
		addButton(generateBankCollection);
	}
	
	@Override
	protected void addSearchFields() {
		super.addSearchField(convertPropertyToField(DEPTIDS, EMPLOYEE, ACCTTERM, STATE));
	}
	
	@Override
	protected void addListFields() {
		addListField(convertPropertyToField(STATE, EMPLOYEE, ACCTTERM, AMOUNT, PAYMODEL, DEPARTMENT, CREATED, CREATEDON));
	}
	
	@Override
	protected void addDetailFields() {
		addDetailField(convertPropertyToField(EMPLOYEE, ACCTTERM, AMOUNT, PAYMODEL, STATE));
	}
	
	@Override
	protected void gatherExproperties() {
		exProperties.put(REQUIRED, new String[]{EMPLOYEE});
	}
	
	protected RelatedModel[] getRelatedModels(){
		RelatedModel getLayout = new RelatedModel(this.clazz, "getLayout");
		return new RelatedModel[]{getLayout};
	}
	
	protected TabbedModel[] getTabbedModels(){
		TabbedModel salaryItem = new TabbedModel(SalaryItemBase.class, SEARCHRELATEDRESULT, "parent");
		
		TabbedModel salaryTickets = new TabbedModel(SalaryTicket.class, SEARCHRELATEDRESULT);
		return new TabbedModel[]{salaryItem, salaryTickets};
	}
	
	@Override
	protected void afterBuilderLayout() {
		DetailLayout recal = createDetailLayout(model, reCalcSalary.getName(), false, convertPropertyToField(ACCTTERM, STATE, DEPTIDS, EMPLOYEE));
		bindButtonToLayout(reCalcSalary, recal);
		
		bindButtonToLayout(generateBankCollection, getModel(BankCollection.class).getDefaultDetailLayout());
		
//		bindButtonToLayout(pay, getDefaultDetailLayout());
		super.afterBuilderLayout();
		
		
	}
	
}
